package com.supermap.dataservice.order.dao;

import com.supermap.dubbo.api.order.entity.Function;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author:langhongshuai
 * @Description:功能数据访问层
 * @Date:18/6/19 上午10:14
 */
@Mapper
public interface FunctionDao {

    /**
     * 通过用户id获取用户的功能定制信息
     * @param userid
     * @return
     */
    @Select("select t1.*,if(ISNULL(t2.id),'0','1') as flag from t_function t1 "
            + "left join t_user_function t2 on t1.ID = t2.functionid and t2.userid = #{userid};")
    List<Function> getAllFunctionByUserId(@Param("userid") int userid);


    /**
     * 用户功能定制
     * @param userid
     * @param functionid
     */
    @Insert("Insert into t_user_function(userid,functionid) values(#{userid},#{functionid})")
    void addUserFunction(@Param("userid") int userid, @Param("functionid") int functionid);

    /**
     * 用户定制功能删除
     * @param userid
     * @param functionid
     */
    @Delete("delete from t_user_function where userid=#{userid} and functionid=#{functionid}")
    void delUserFunction(@Param("userid") int userid, @Param("functionid") int functionid);

    /**
     * 通过用户id和功能id检查功能是否被用户定制
     * @param userid
     * @param functionid
     * @return
     */
    @Select("select t1.*,if(ISNULL(t2.id),'0','1') as flag from t_function t1 "
            + "left join t_user_function t2 on t1.ID = t2.functionid "
            + "where t2.userid = #{userid} and t2.functionid=#{functionid}")
    List<Function> checkUserFunctionExist(@Param("userid") int userid, @Param("functionid") int functionid);
}
